<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta charset="utf-8">
    <title>会员账户编辑</title>
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/favicon.ico"/>
    <link rel="bookmark" href="${pageContext.request.contextPath}/favicon.ico"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/webjars/layui/css/layui.css" media="all">
    <script type="application/javascript" src="${pageContext.request.contextPath}/webjars/layui/layui.js"
            charset="utf-8"></script>
    <script type="application/javascript" src="${pageContext.request.contextPath}/webjars/jquery/jquery.js"></script>
    <script type="application/javascript"
            src="${pageContext.request.contextPath}/private/js/loading/ajaxloading.js"></script>
</head>
<body>
<form id="form1" class="layui-form" action="">
    <table width="96%" align="center">
        <tr height="23">
            <td align="center">孩子姓名:</td>
            <td align="left">
                <input type="hidden" id="cid" name="cid" value="${childrenInfo.cid}">
                <input type="hidden" id="userid" name="userid" value="${childrenInfo.userid}">
                <input id="cname" name="cname" class="layui-input" type="text" placeholder="请输入孩子姓名" autocomplete="off"
                       lay-verify="username" value="${childrenInfo.cname}">
            </td>
        </tr>
        <tr height="23">
            <td align="center">性别:</td>
            <td align="left">
                <input id="csex" name="csex" type="checkbox" lay-skin="switch" value="${childrenInfo.csex}" ${childrenInfo.csex=="2"?"":"checked"}
                       lay-text="男|女">
            </td>
        </tr>
        <tr height="23">
            <td align="center">出生日期:</td>
            <td align="left">
                <input id="birthday" name="birthday" class="layui-input" type="text" placeholder="yyyy-MM-dd"
                       autocomplete="off" value="${birthday_str}"
                       lay-verify="birthday">
            </td>
        </tr>
        <tr height="50">
            <td align="center">
                <button id="formsubmit" class="layui-btn" lay-submit lay-filter="savechildreninfo">保存</button>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="application/javascript">
    var form;
    layui.use(['form','laydate'], function(){
        form = layui.form;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#birthday' //指定元素
        });

        //switch off状态赋值
        form.on('switch', function (data) {
            $(data.elem).attr('type', 'hidden').val(this.checked ? '1' : '2');
        });
        //表单验证规则自定义
        form.verify({
            cname: function(value){
                if(!value) {
                    return '孩子姓名不能为空';
                }
            },
            birthday: function(value){
                if(!value) {
                    return '孩子出生日期不能为空';
                }
            }
        });

        //监听提交
        form.on('submit(savechildreninfo)', function(data){
            $.ajax({
                data : data.field,
                type : "POST",
                url : "${pageContext.request.contextPath}/eyas/userinfo/saveChildrenInfo",
                dataType : "json",
                success: function(data) {
                    layer.msg("保存成功,页面将在1秒后关闭");
                    setTimeout(function () {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    },1000);
                },
                error:function(xdata){
                    layer.msg(xdata.responseJSON.errormsg);
                }
            });
            return false;
        });
    });
</script>
</html>
